package com.cssy.authority.dao.impl;

import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.cssy.authority.dao.ScDepartmentDAO;
import com.cssy.authority.entity.ScDepartmentDO;
import com.plat.helper.SearchConditions;

/**
 * 数据访问对象实现类
 * @since 2013-04-24
 */
public class ScDepartmentDAOImpl extends SqlMapClientDaoSupport implements ScDepartmentDAO {

    /**
     * 插入数据
     * @param basicDepartmentDO
     * @return 插入数据的主键
     */
    public String insertBasicDepartmentDO(ScDepartmentDO basicDepartmentDO) throws DataAccessException {
        Object id = getSqlMapClientTemplate().insert("ScDepartment.insert", basicDepartmentDO);
        return (String) id;
    }

    /**
     * 统计记录数
     * @param basicDepartmentDO
     * @return 查出的记录数
     */
    public Integer countBasicDepartmentDOByExample(ScDepartmentDO basicDepartmentDO) throws DataAccessException {
        Integer count = (Integer) getSqlMapClientTemplate().queryForObject("ScDepartment.countByDOExample", basicDepartmentDO);
        return count;
    }

    /**
     * 更新记录
     * @param basicDepartmentDO
     * @return 受影响的行数
     */
    public Integer updateBasicDepartmentDO(ScDepartmentDO basicDepartmentDO) throws DataAccessException {
        int result = getSqlMapClientTemplate().update("ScDepartment.update", basicDepartmentDO);
        return result;
    }

    /**
     * 获取对象列表
     * @param basicDepartmentDO
     * @return 对象列表
     */
    @SuppressWarnings("unchecked")
    public List<ScDepartmentDO> findListByExample(ScDepartmentDO basicDepartmentDO) throws DataAccessException {
        List<ScDepartmentDO> list = getSqlMapClientTemplate().queryForList("ScDepartment.findListByDO", basicDepartmentDO);
        return list;
    }

    /**
     * 根据主键获取basicDepartmentDO
     * @param id
     * @return basicDepartmentDO
     */
    public ScDepartmentDO findBasicDepartmentDOByPrimaryKey(String id) throws DataAccessException {
        ScDepartmentDO basicDepartmentDO = (ScDepartmentDO) getSqlMapClientTemplate().queryForObject("ScDepartment.findByPrimaryKey", id);
        return basicDepartmentDO;
    }

    /**
     * 删除记录
     * @param id
     * @return 受影响的行数
     */
    public Integer deleteBasicDepartmentDOByPrimaryKey(String id) throws DataAccessException {
        Integer rows = (Integer) getSqlMapClientTemplate().delete("ScDepartment.deleteByPrimaryKey", id);
        return rows;
    }

    @Override
   	public List<ScDepartmentDO> find(SearchConditions scs)
   			throws DataAccessException {
   		List<ScDepartmentDO> list = getSqlMapClientTemplate().queryForList("ScDepartment_ex.find", scs);
   		   return list;
   	}

   	@Override
   	public Integer count(SearchConditions scs) throws DataAccessException {		
   		 Integer count = (Integer) getSqlMapClientTemplate().queryForObject("ScDepartment_ex.count", scs);
   	      return count;
   	}
}